package com.example.shirotest.study;

public class ExceptionTest {

    public static void main(String[] args) {

        String account = "admin";
        String password = "admin";

        try {
            login(account,password);
        }catch (AccountException e){
            System.out.println("Account Error");
            return;
        }catch (PasswordException e){
            System.out.println("Password Error");
            return;
        }catch (LoginException e){
            System.out.println("Other exception");
            return;
        }finally {
            System.out.println("finally run");
        }



        System.out.println("Main process end");
    }


    public static void login(String account,String password){
        if(!"admin".equals(account)){
            throw new AccountException("账号不正确");
        }
        if(!"admin".equals(password)){
            throw new PasswordException("密码不正确");
        }
        System.out.println("Login success");
    }

}

class AccountException extends LoginException{
    public AccountException(String message){
        super(message);
    }
}

class PasswordException extends LoginException{
    public PasswordException(String message){
        super(message);
    }
}

//TODO 自定义异常
class LoginException extends RuntimeException{
    public LoginException(String message){
        super(message);
    }
}
